/*
 * Copyright 2015-2016 Tumblr, Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.tumblr.backboard.imitator;

import com.facebook.rebound.Spring;
import com.facebook.rebound.SpringListener;

/**
 * The default implementation sets the end value of the attached Spring to be the same as the current value of the
 * couple it is imitating.
 *
 * @author ericleong
 * @since 2021-05-07
 */
public class SpringImitator extends Imitator implements SpringListener {
    /**
     * spring imitator
     *
     * @param spring the spring to imitate
     */
    public SpringImitator(Spring spring) {
        super(spring);
    }

    /**
     * Constructor.
     *
     * @param spring the spring to imitate.
     * @param trackStrategy the tracking strategy.
     * @param followStrategy the follow strategy.
     */
    protected SpringImitator(Spring spring, int trackStrategy, int followStrategy) {
        super(spring, trackStrategy, followStrategy);
    }

    /**
     * Constructor.
     *
     * @param spring the spring to imitate.
     * @param restValue the spring value when not being perturbed.
     * @param trackStrategy the tracking strategy.
     * @param followStrategy the follow strategy.
     */
    protected SpringImitator(Spring spring, double restValue, int trackStrategy, int followStrategy) {
        super(spring, restValue, trackStrategy, followStrategy);
    }

    @Override
    protected double mapToSpring(float motionValue) {
        return motionValue;
    }

    @Override
    public void onSpringUpdate(Spring spring) {
        mSpring.setEndValue(spring.getCurrentValue());
    }

    @Override
    public void onSpringAtRest(Spring spring) {
    }

    @Override
    public void onSpringActivate(Spring spring) {
    }

    @Override
    public void onSpringEndStateChange(Spring spring) {
    }
}
